<?php
echo $javascript->codeBlock("
	$(document).ready(function(){
		$('#button_lista_uzytkownikow').click(function() {
		  $('#dialog_lista_uzytkownikow').dialog({width: 650, height: 600});
		});
		
		$('.chackbox_select_user').click(function(){
			UserID = $(this).val();
			if ($(this).is(':checked')){
				alert($(this).attr('title'));
		  		$('#MessageUsers').val($('#MessageUsers').val() + $(this).attr('title') + ';');
		  		$('#MessageUserId'+UserID).attr('value',UserID);
		  	}else{
		  		alert($(this).attr('title'));
		  		tresc = $('#MessageUsers').val();
		  		$('#MessageUsers').val(tresc.replace($(this).attr('title')+';', ''));
		  		$('#MessageUserId'+UserID).attr('value',0);
		  	}
		});
		
		$('input#id_search').quicksearch('table#table_users_list tr');
	});		
",$options = array('allowCache'=>false,'safe'=>false,'inline'=>false));
?>
<div class="main_body">
	<div id="left_column">
    <?php echo $this->element('main_menu')?>
    </div>    	
	<div id="main_body_content">

		<div class="messages form">
		
		<?php //echo $this->Form->create('Message');?>
		<?php
			echo $javascript->link('ckeditor/ckeditor');
			echo $cksource->create("Message",array('url'=>array('action'=>'add'))); 
			$config['toolbar'] = array( 
			    array( 'Source', '-', 'Bold', 'Italic', 'Underline', 'Strike' ), 
			    array( 'Image', 'Link', 'Unlink', 'Anchor' ) 
			); 
			$config['height'] = 350;
		?>	
				
			<fieldset>
		 		<legend><h1><?php __("New Message");?></h1></legend>
		 		<table width="100%">
		 			<tr>
		 				<td>
		 					<?php echo __("To",true)?>
		 				</td>
		 				<td>
		 					<?php echo $this->Form->input('users',array('id'=>'MessageUsers','label'=>false,'type'=>'text','style'=>'width: 100%;'));?>
		 					<?php 
		 						foreach ($users as $user_id => $user){
		 							echo $this->Form->hidden('Message.user_id.'.$user_id,array('value'=>0));
		 						}
		 					?>
		 				</td>
		 				<td align="left"><input id="button_lista_uzytkownikow" type="button" value="..."/></td>
		 			</tr>
		 			<tr>
		 				<td><?php echo  __("Subject",true)?></td>
						<td colspan="2">
							<?php echo $this->Form->input('name',array('label'=>false,'style'=>'width: 100%;'));?>
						</td>
		 			</tr>
		 		</table>			
			</fieldset>
			<?php 	
				echo $cksource->ckeditor('Message.content', array( 'config'=>$config));				
			?>
			
		<?php echo $this->Form->end(__("Send", true));?>
		</div>
		
		<div id="dialog_lista_uzytkownikow" title="<?php echo __("Users List",true)?>">
 			<div class="select_user_from_list index">
 				<form action="#">
					<fieldset>
						<div class="input text required">
						<label for="search"><?php __("Szukaj")?></label>
						<input type="text" name="search" value="" id="id_search" placeholder="Search" autofocus=""/>
						</div>
					</fieldset>
				</form>
				<table cellpadding="0" cellspacing="0" id="table_users_list">
				<?php
				$i = 0;
				foreach ($users as $user_id => $user):
					$class = null;
					if ($i++ % 2 == 0) {
						$class = ' class="altrow"';
					}
				?>
				<tr<?php echo $class;?>>
					<td>
						<?php $checked = (isset($this->data["Message"]["user_id"]) &&  is_array($this->data["Message"]["user_id"]) && array_key_exists($user_id, $this->data["Message"]["user_id"]) && $this->data["Message"]["user_id"][$user_id] == $user_id ) ? "checked": ""?>
						<?php echo $this->Form->checkbox('users.'.$user_id,array('class'=>'chackbox_select_user','value'=>$user_id,'title'=>$user['email'], 'checked'=>$checked) );?>
					</td>
					<td><?php echo $user['email']; ?> &nbsp;</td>
					<td><?php echo (isset($user['name']))?$user['name']:''; ?> <?php echo (isset($user['surname']))? $user['surname']:''; ?>&nbsp;</td>
					<td>
						<?php 
							$groups = Configure::read('Config.users_groups');
							echo $groups[$user['group']]['name'];
						?>							
					</td>
					<td class="actions">
						<?php echo (isset($user['address1']))? $user['address1'] :''; ?> <?php echo (isset($user['address3']))? $user['address3'] : ''; ?>&nbsp;
					</td>
				</tr>
			<?php endforeach; ?>
				</table>					
 			</div>
 		</div>
 		
		<div class="clr"></div>	
	</div>			
	<?php echo $this->element('languages')?>	
	<div class="clr"></div>
</div>	
<div class="clr"></div>	
<div class="main_action">
	<div class="main_action_content">
		
		<div class="actions">
			<h3><?php __("Actions"); ?></h3>
			<ul>		
				<li><?php echo $this->Html->link($html->image(HOST.'/actions_message_inbox.png'), array( 'action' => 'index',1),array('escape'=>false,'title'=>__("Inbox", true))); ?> <div class="clr"></div> <?php echo __("Inbox", true)?></li>
				<li><?php echo $this->Html->link($html->image(HOST.'/actions_message_outbox.png'), array( 'action' => 'index',2),array('escape'=>false,'title'=>__("Outbox", true))); ?> <div class="clr"></div> <?php echo __("Outbox", true)?></li>				
				<li><?php echo $this->Html->link($html->image(HOST.'/actions_message_archivies.png'), array( 'action' => 'index',3),array('escape'=>false,'title'=>__("Archives", true))); ?> <div class="clr"></div> <?php echo __("Archives", true)?></li>				
				<li><?php echo $this->Html->link($html->image(HOST.'/actions_messages_deleted.png'), array( 'action' => 'index',4),array('escape'=>false,'title'=>__("Deleted Items", true))); ?> <div class="clr"></div> <?php echo __("Deleted Items", true)?></li>
			</ul>
		</div>

		<div class="clr"></div>
	</div>		
</div>				